package com.group01.validation;

import com.group01.annotation.ImageAddress;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ImageAddressValidation implements ConstraintValidator<ImageAddress, String> {

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        String regex = "^(http|https)\\:\\/\\/[a-zA-Z0-9\\.\\-]+\\.[a-zA-Z]{2,3}(\\/[^\\s]*)*\\.(jpg|jpeg|png|gif|bmp)$";

        Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(value);

        return matcher.matches();
    }
}
